//
// Created by Rory on 2020/10/5.
//
#define GENERATE_TEST_FUNC_SIGNATURE
#include "sequentiallist.h"
#include "linkedlist.h"

void TestFunc__SeqList__(){
    SeqListPtr  list = NULL;
    InitSeqList(&list,0,sizeof(int));

    int a = 18;
    int b = 22;
    list->Append(list,&a);
    list->Append(list,&b);
    list->Append(list,&b);
    list->Append(list,&b);
    list->Append(list,&b);
    list->Append(list,&b);
    list->Append(list,&b);
    list->Append(list,&b);
    list->IntPrint(list);
    printf("capacity:%d,length:%d\n",list->capacity,list->length);
    DestroySeqList(list);
}

void TestFunc__LinkedList__(){
    SingularLList singularLList;
    InitSingularLList(&singularLList);
    singularLList.Append(&singularLList,1);
    singularLList.Append(&singularLList,2);
    singularLList.Append(&singularLList,3);
    singularLList.Append(&singularLList,4);
    Node p = singularLList.head;
    while (p->next!=NULL){
        p = p->next;
        printf("%d ",p->data);
    }
    DestroyLinkedList(&singularLList);
}

void TestFunc__DeleteElementRecursively__(){
    SingularLList singularLList;
    InitSingularLList(&singularLList);
    singularLList.Append(&singularLList,4);
    singularLList.Append(&singularLList,41);
    singularLList.Append(&singularLList,4);

    //删除所有值为4的结点
    DeleteElementRecursively(&singularLList,singularLList.head,4);

    //打印元素，验证结果
    Node p = singularLList.head;
    while (p->next!=NULL){
        p = p->next;
        printf("%d ",p->data);
    }

    DestroyLinkedList(&singularLList);
}

void TestFunc__IntPrintConverselyRecursively__(){
    SingularLList singularLList;
    InitSingularLList(&singularLList);
    singularLList.Append(&singularLList,1);
    singularLList.Append(&singularLList,2);
    singularLList.Append(&singularLList,3);
    singularLList.Append(&singularLList,2);
    singularLList.Append(&singularLList,55);
    IntPrintConverselyRecursively(singularLList.head->next);
    DestroyLinkedList(&singularLList);
}

//开始采用宏编写测试函数，免去冗长的函数签名申明
TestFunc(ReverseSingularList){
    SingularLList singularLList;
    InitSingularLList(&singularLList);
    singularLList.Append(&singularLList,1);
    singularLList.Append(&singularLList,2);
    singularLList.Append(&singularLList,3);
    IntPrintRecursively(singularLList.head);
    printf("\n");
    ReverseSingularList(&singularLList);
    IntPrintRecursively(singularLList.head);
    DestroyLinkedList(&singularLList);
}

int main(){

    //TestFunc__SeqList__();
    //TestFunc__LinkedList__();
    //TestFunc__DeleteElementRecursively__();
    //TestFunc__IntPrintConverselyRecursively__();
    Func(ReverseSingularList);
    return 0;
}

